package com.gzk.system.controller;

import com.gzk.basic.config.SignId;
import com.gzk.basic.util.AjaxResult;
import com.gzk.basic.util.PageList;
import com.gzk.system.domain.Systemdictionarydetail;
import com.gzk.system.query.SystemdictionarydetailQuery;
import com.gzk.system.service.ISystemdictionarydetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/detail")
@Api(tags = "字典细节接口",description = "字典细节接口详细描述")
public class SystemdictionarydetailController {

    //注入
    @Autowired
    private ISystemdictionarydetailService systemdictionarydetailService;

    @GetMapping("/{id}")
    public Systemdictionarydetail getById(@PathVariable("id") Long id){
        return systemdictionarydetailService.queryById(id);
    }

    @GetMapping("/list")
    public List<Systemdictionarydetail> getAll(){
        return systemdictionarydetailService.queryAll();
    }

    @PostMapping("/page")
    public PageList<Systemdictionarydetail> pageQuery(@RequestBody SystemdictionarydetailQuery query){
        System.out.println(query);
        return systemdictionarydetailService.queryPage(query);
    }

    @ApiOperation(value = "员工添加或修改",notes = "如果有id就是修改否则就是添加")
    @PostMapping("/save")
    public AjaxResult saveOrUpdate(@RequestBody Systemdictionarydetail systemdictionarydetail){
        try {
            //判断
            if(systemdictionarydetail.getId() == null){
                //增加
                systemdictionarydetailService.add(systemdictionarydetail);
            }else {
                //修改
                systemdictionarydetailService.update(systemdictionarydetail);
            }
            //成功
            return AjaxResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            //失败
            return AjaxResult.ok().setSuccess(false).setMessage("系统繁忙！！");
        }
    }

    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable("id") Long id){
        try {
            systemdictionarydetailService.remove(id);
            return AjaxResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            //失败
            return AjaxResult.ok().setSuccess(false).setMessage("系统繁忙！！");
        }
    }

    @PatchMapping("/batch")
    public AjaxResult deleteMany(@RequestBody List<Long> ids){
        try {
            systemdictionarydetailService.removeMany(ids);
            return AjaxResult.ok();
        } catch (Exception e) {
            e.printStackTrace();
            //失败
            return AjaxResult.ok().setSuccess(false).setMessage("系统繁忙！！");
        }
    }
    @GetMapping("/setSign/{id}")
    public void setSign(@PathVariable("id") Long id){
        SignId.INSTANCE.setSignId(id);
    }

    @GetMapping("/getSign")
    public Long getSign(){
       return SignId.INSTANCE.getSignId();
    }

}
